package com.ItemsRent.IService.service;

import java.util.List;

import com.ItemsRent.IDao.dao.BaseDAO;
import com.ItemsRent.IService.IOrderForm;
import com.ItemsRent.model.Customer;
import com.ItemsRent.model.OrderForm;

public class OrderFormImpl implements IOrderForm {
	private BaseDAO<OrderForm> orderFormDao;

	public BaseDAO<OrderForm> getOrderFormDao() {
		return orderFormDao;
	}

	public void setOrderFormDao(BaseDAO<OrderForm> orderFormDao) {
		this.orderFormDao = orderFormDao;
	}

	public void insert(OrderForm orderForm) {
		orderFormDao.save(orderForm);
	}

	public void delete(OrderForm orderForm) {
		orderFormDao.delete(orderForm);
	}

	public void update(OrderForm orderForm) {
		orderFormDao.update(orderForm);
	}

	public OrderForm findByOrderId(int id) {
		return orderFormDao.find(OrderForm.class, id);
	}
	
	public List<OrderForm> findByCustomerId(int id) {
		String hql = "select o from OrderForm o where o.customer.customerId= '"+ id + 
				"'and o.orderStatus=0";
		List<OrderForm> list = orderFormDao.list(hql);
		return list;
	}

	public List<OrderForm> findAllBook(int customerId) {
		String hql = "select o from OrderForm o where o.customer.customerId= '"
				+ customerId + "'and o.orderStatus=1";
		// System.out.println(hql);
		List<OrderForm> list = orderFormDao.list(hql);
		return list;
	}

	public List<OrderForm> findAllReceive(int customerId) {
		String hql = "select o from OrderForm o where o.item.customer.customerId= '"
				+ customerId + "'";
		List<OrderForm> list = orderFormDao.list(hql);
		return list;
	}
}
